﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace Linkmeme.Models
{
    public partial class LinkmemeDataContext
    {

        public List<UserSelectedProvider> GetProvidersByUser(Guid userId)
        {
            var ps = from ucp in UserContentProviders
                     where ucp.UserId == userId
                     select new UserSelectedProvider
                     {
                         ID = ucp.ID,
                         ProviderID = ucp.ProviderID,
                         ProviderName = ucp.ContentProvider.Name,
                         ProviderUserName = ucp.ProviderUserName,
                         ProviderType = ucp.ContentProvider.SourceType
                     };
            return ps.ToList();
        }

        public List<UserSelectedProvider> GetProvidersByType(Guid userId, string providerType)
        {
            return GetProvidersByUser(userId).Where(ucp => ucp.ProviderType.ToLower() == providerType.ToLower()).ToList();
        }

        //public List<User> GetFriends(Guid userId)
        //{
        //    return (from uf in UserFriends
        //                  join u in Users on uf.FriendId equals u.UserId
        //                  where uf.UserId == userId
        //                  select u).ToList();
                          
        //}


    }

    public partial class User
    {
        public IEnumerable<User> Friends
        {
            get 
            {
                return this.UserFriends.Select(uf => uf.User1);
            }
        }
    }

   
}
